/* URBAN EXPLORER PROJECT
 * 
 * Author: Karthick Nanmaran (s1051713), School of Informatics, The University of Edinburgh
 * Email: karthicknanmaran@gmail.com
 * 
 * Supervisor: Dr.William Mackaness, 
 * 			   Institute of Geography,
 * 			   School of GeoSciences,
 * 			   The University of Edinburgh.
 * Email: william.mackaness@ed.ac.uk
 * 
 * This code can be found online at http://code.google.com/p/urban-explorers/
*/
package Firstdroid.Gps;
import Firstdroid.Gps.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity 
{
    /** Called when the activity is first created. */
   @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        /* Alert Dialog Box that pops up and asks the user to Turn on GPS if it is off */
        LocationManager LM = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
		if (!LM.isProviderEnabled(LocationManager.GPS_PROVIDER)){ 
	        AlertDialog.Builder builder = new AlertDialog.Builder(this);
	        	builder.setMessage("It seems your GPS is disabled! This app requires you to enable your GPS. Would you like to enable it?")
	                .setCancelable(false).setPositiveButton("Enable GPS", new DialogInterface.OnClickListener() { 
	                	public void onClick(DialogInterface dialog, int id) { 
	                		Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
	                    		startActivity(gpsOptionsIntent); }  });
	        	builder.setNegativeButton("Do nothing", new DialogInterface.OnClickListener() {
	                    public void onClick(DialogInterface dialog, int id) {
	                        dialog.cancel(); }   });
	        AlertDialog alert = builder.create();
	        alert.show();
	    }
        
        /* TRACKER BUTTON */
        
        Button startButton = (Button) findViewById(R.id.buttonStart);
        startButton.setOnClickListener(new View.OnClickListener() 
        {
                @Override
                public void onClick(View v){
                		Log.d("Firstdroid.Gps", "Starting Exploration..");
                        // Start Urban Exploration
                        startActivity(new Intent(MainActivity.this, Tracker.class));
                }
        });
        
        /* MAP BUTTON */

        Button mapButton = (Button) findViewById(R.id.buttonMap);
        mapButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v){
                    Log.d("Firstdroid.Gps", "Loading Map..");
                    // Loading Google Map View
                    //Intent in = new Intent(MainActivity.this, MapViewer.class);
                    //startActivity(in);
                    startActivity(new Intent(MainActivity.this, MapViewer.class));
                    
                }       
        });

        
        /* SPEAK BUTTON */

        Button speakButton = (Button) findViewById(R.id.buttonSpeak);
        speakButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View x){
                    Log.d("Firstdroid.Gps", "Loading Layout");
                    // Loading Google Map View
                    //Intent in = new Intent(MainActivity.this, MapViewer.class);
                    //startActivity(in);
                    /*if(x==buttonSpeak){ 
                        // doStuff
                        Intent intentMain = new Intent(MainActivity.this , VoiceRecTextSpeech.class);
                        CurrentActivity.this.startActivity(intentMain);
                        Log.i("Content "," Main layout ");
*/
                    //setContentView(R.layout.voice);
                    startActivity(new Intent(MainActivity.this, SVRTS.class));                    
                }       
        });
        
        /* BLUETOOTH BUTTON */
        
        Button bluetoothButton = (Button) findViewById(R.id.buttonBluetooth);
        bluetoothButton.setOnClickListener(new View.OnClickListener() 
        {
                @Override
                public void onClick(View v){
                		Log.d("Firstdroid.Gps", "Starting Bluetooth Activity..");
                        // Starting Bluetooth Activity
                        startActivity(new Intent(MainActivity.this, BluetoothActivity.class));
                }
        });
        
        /* STATISTICS BUTTON */
        
        Button statisticsButton = (Button) findViewById(R.id.buttonStatistics);
        statisticsButton.setOnClickListener(new View.OnClickListener() 
        {
                @Override
                public void onClick(View v){
                		Log.d("Firstdroid.Gps", "Displaying GPS Statistics..");
                        // Displaying GPS Statistics
                        startActivity(new Intent(MainActivity.this, Statistics.class));
                }
        });
        

        /* STOP BUTTON */
        Button stopButton = (Button) findViewById(R.id.buttonStop);
        stopButton.setOnClickListener(new OnClickListener() 
        {
                @Override
                public void onClick(View v) 
                {
                Log.d("Firstdroid.Gps", "Stopping Exploration..");
                // Stop Urban Exploration
                System.exit(0);
                //finish();
        }
        });
    }
}/* End of MainActivity */
        //MapView mapView = (MapView) findViewById(R.id.mapview);
        //mapView.setBuiltInZoomControls(true);
